/*
 * ld script to make ARM Chushi kernel
 * taken from the i386 version by Russell King
 * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
 */

#include <asm/process.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/memory.h>
#include <asm/cache.h>
#include <asm/exception.h>
#define LOAD_OFFSET ((KERNEL_VA_START) + TEXT_OFFSET)
#include <asm-generic/vmlinux.lds.h>

OUTPUT_ARCH(riscv)
ENTRY(kernel_text_start)

jiffies = jiffies_64;

SECTIONS
{
	/* Beginning of code and text segment */
	. = LOAD_OFFSET;
	kernel_text_start = .;
	PROVIDE(_code_start = .);
	PROVIDE(_init_text_start = .);	
	__init_begin = .;
	HEAD_TEXT_SECTION
	INIT_TEXT_SECTION(PAGE_SIZE)
	INIT_DATA_SECTION(16)
	/* we have to discard exit text and such at runtime, not link time */
	.exit.text :
	{
		EXIT_TEXT
	}
	.exit.data :
	{
		EXIT_DATA
	}
	
	PROVIDE(_cpio_start = .);
	.cpio ALIGN(8) :
	{
		KEEP(*(.cpio))
	}
	PROVIDE(_cpio_end = .);

	PERCPU_SECTION(L1_CACHE_BYTES)
	__init_end = .;
	PROVIDE(_init_text_end = .);

	PROVIDE(_text_start = .);
	.text : {
		_text = .;
		_stext = .;
		TEXT_TEXT
		SCHED_TEXT
		LOCK_TEXT
		KPROBES_TEXT
		ENTRY_TEXT
		IRQENTRY_TEXT
		*(.fixup)
		_etext = .;
	}
	PROVIDE(_text_end = .);

	/* Start of data section */
	_sdata = .;
	RO_DATA_SECTION(L1_CACHE_BYTES)
	.srodata : {
		*(.srodata*)
	}
	
	. = ALIGN(4);
	.altinstructions : {
		__alt_instructions = .;
		*(.altinstructions)
		__alt_instructions_end = .;
	}
	.altinstr_replacement : {
		*(.altinstr_replacement)
	}

	RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
	.sdata : {
		__global_pointer$ = . + 0x800;
		*(.sdata*)
		/* End of data section */
		_edata = .;
		*(.sbss*)
	}

	BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0)

	. = ALIGN(PAGE_SIZE);
	pgtbl_root_idmap = .;
	. += IDMAP_DIR_SIZE;
	. = ALIGN(PAGE_SIZE);
	pgtbl_root = .;
	. += GLOBAL_DIR_SIZE;

	. = ALIGN(PROCESS_STACK_SIZE);
	.init_stack :
	{
		PROVIDE(init_stack_start = .);
		. = . + (PROCESS_STACK_SIZE);
		. = ALIGN(8);
		PROVIDE(init_stack_end = .);
	}

	EXCEPTION_TABLE(0x10)
	NOTES

	.rel.dyn : {
		*(.rel.dyn*)
	}

	_end = .;

	kernel_text_end = .;
	PROVIDE(_code_end = .);

	STABS_DEBUG
	DWARF_DEBUG

	DISCARDS
}

